const router = require('koa-router')();

router.prefix('/api')

// 写你自己的路由
router.post('/lx', async ctx => {
    let { powd, user } = ctx.request.body
    let res = await ctx.searchQuery(`select * from lx where user="${user}"`)
    if (res.length) {
        ctx.body = {
            code: 200,
            msg: "该用户已注册"
        }
        return;
    }
    //添加
    const addres = await ctx.searchQuery(`INSERT INTO lx ( powd ,user)
    VALUES 
    ( '${powd}','${user}' );`);
    console.log(addres);
    ctx.body = {
        code: 200,
        msg: "注册成功" 
    }
})

router.post('/logins', async ctx => {
    const { powd, user } = ctx.request.body;
    const res = await ctx.searchQuery(`select * from lx WHERE powd='${powd}' AND user='${user}';`);
    if (res.length) {
        ctx.body = {
            code: "SUCCESS",
            msg: "登录成功",
            }
       status: 200
         return;
    }
    ctx.body = {
        code: "FAIL",
        msg: "用户名密码输入有误",
        status: 200
    }
})



module.exports = router;